package com.yunying.rispro.service.impl;

import com.yunying.rispro.exception.BusinessException;
import com.yunying.rispro.model.Patients;
import com.yunying.rispro.mapper.PatientsMapper;
import com.yunying.rispro.service.IPatientsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunying.rispro.util.JsonResponseBody;
import com.yunying.rispro.util.JsonResponseStatus;
import com.yunying.rispro.util.PinYinUtil;
import com.yunying.rispro.vo.AddVo;
import com.yunying.rispro.vo.RisVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 患者信息表 服务实现类
 * </p>
 *
 * @author yunying
 * @since 2022-04-21
 */
@Service
public class PatientsServiceImpl extends ServiceImpl<PatientsMapper, Patients> implements IPatientsService {

    @Autowired
    private PatientsMapper patientsMapper;

    @Override
    public JsonResponseBody<?> addPatients(Patients patients) {
        patients.setId(10+new Date().getTime());
        patients.setPatientsPinyin(PinYinUtil.getPingYin(patients.getPatientsName()).toLowerCase());
        int i=patientsMapper.insertPatients(patients);
        if(i<0){
            throw new BusinessException(JsonResponseStatus.OPERATE_ERROR);
        }
        return new JsonResponseBody<>();
    }

    @Override
    public JsonResponseBody<?> updatePatients(Patients patients) {
        int i = patientsMapper.updateById(patients);
        if(i<0){
            throw new BusinessException(JsonResponseStatus.OPERATE_ERROR);
        }
        return new JsonResponseBody<>();
    }
}
